package cn.emailChat.ai.replychain;

import cn.emailChat.ai.dto.MailInboundEvent;

/**
 * @Description 责任链抽象类
 * @Author susu
 * @Date 2025/8/18
 */
public abstract class AbstractReplyHandler implements ReplyHandler{
    private ReplyHandler next;

    @Override
    public ReplyHandler setNext(ReplyHandler next) {
        this.next = next;
        return next;
    }

    @Override
    public String handle(MailInboundEvent event) {
        String ans = tryHandle(event);          // 子类尝试处理
        if (ans != null && !ans.trim().isEmpty()) {
            return ans;
        }
        return (next == null) ? null : next.handle(event); // 否则交给下一个
    }

    /** 子类具体实现：返回null/空串则表示放行给下一位 */
    protected abstract String tryHandle(MailInboundEvent event);
}
